<?php
/**
 * Created by PhpStorm.
 * User: 14775
 * Date: 2017/9/19
 * Time: 10:42
 */

namespace Wx\Controller;


use Common\Controller\HomebaseController;
use Common\Lib\JSSDK;
use Common\ModelSQ\ERPUser;
use Common\ModelSQ\ModelSQBase;

class GetController extends HomebaseController
{
    public function accessToken()
    {
        $api_users = C('API_USERS');
        //验证
        $params = I('');
        $api_sign = $params['sign'];
        $api_appid = $params['apiid'];
        $api_appsecret = $api_users[$api_appid];

        unset($params['sign']);
        $params['apisecret'] = $api_appsecret;
        ksort($params);
        $str_parmas = http_build_query($params);

        error_log(print_r($str_parmas, 1));
        if ($api_sign == md5($str_parmas)) {

            $weixin = C('WEIXIN');
            $appid = $weixin['APPID'];
            $appsecret = $weixin['APPSECRET'];

            $jssdk = new JSSDK($appid, $appsecret);

            $data = array(
                'appid' => $appid,
                'access_token' => $jssdk->getAccessToken(),
                'status' => 200
            );
            $this->ajaxReturn($data);
        } else {
            $this->ajaxReturn(array('status' => 0));
        }
    }

    public function test()
    {
        $erpUser = new ERPUser();

//        $data = array(
//            'issue_store'=>'02101',
//            'telephone'=> '18616026084',
//            'member_name_chn'=>'',
//            'sex'=>'',
//            'address'=>'',
//            'postal_code'=>'',
//            'email'=>'',
//            'certificate_type'=>null,
//            'id_no'=>null,
//         //   'member_code'=>'021010000003'
//        );
//
//        $erpUser->createMember($data);




//        修改
//        $data = array(
//            'issue_store'=>'02101',
//            'telephone'=> '18616026085',
//           'member_name_chn'=>'123123132',
//            'sex'=>'F',
//            'member_code'=>'021010000003',
//            'address'=>'aaaaaaaa',
//            'postal_code'=>'aaaaaaa',
//            'email'=>'aaa@qq.com',
//            'certificate_type'=>null,
//            'id_no'=>null,
//
//        );
//        $erpUser->updateMember($data);

//        查询会员信息
        $data = array(
        'telephone'=>'18616026085'
        );
        $erpUser->getMember($data); //021010000003 , 021010000005




//        $data = array(
//            'member_code'=>'021010000003',
//            'bonus_date'=>'2017-09-27',
//            'bonus_time'=>'10:30:00',
//            'bonus_type'=>'03', //01=消费积分，02=兑换礼品，03=积分调整
//            'bonus_description'=>'调整',
//            'bonus_point'=>100,
//          //  'sales_amount'=>200.00,
//            'store_code'=>'02101'
//        );
//       $aaa=  $erpUser->memberBonusSync($data);
//
//
//        //查询会员积分
//        $erpUser->getMemberBonus(array(
//            'member_code'=>'021010000003',
////            'start_date'=>'2000-01-01',
////            'end_date'=>'2100-01-01'
//        ));


//        $api_appid = '1001';
//        $api_appsecret = 'a7351dcb5d55c069f3290c1746f59ff8';
//
//        $timestamp = date('Y-m-d H:i:s');
//
//        $params = array(
//            'apiid' => $api_appid,
//            'apisecret' => $api_appsecret,
//            'timestamp' => $timestamp
//        );
//        ksort($params);
//
//        $sign = md5(http_build_query($params));
//        $params['sign'] = $sign;
//        unset($params['apisecret']);
//        $result = http_request('http://xiadu.fistforward.com/wx/get/accesstoken', $params);
//
//        $apiinfo = json_decode($result, true);
    }
}